<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <title>我发起的投票</title>
    
    <!-- datepicker -->
    <link href="${ctx}/resource/v2/css/bootstrap-colorpicker.min.css" rel="stylesheet">
    <link href="${ctx}/resource/v2/css/datepicker3.css" rel="stylesheet">
</head>
<body>
	<!-- 菜单及导航数据  -->
    <data id="info" nav="vote" menu="myCreateVote" service="投票服务" action="我发起的投票">

	<div class="row wrapper white-bg animated rotateInUpLeft min-height">
         <div class="row">
           <div class="col-lg-12">
               <div class="ibox float-e-margins">
                   <div class="ibox-title">
                       <h5>我发起的投票 <small class="text-navy">当你无法决定的时候，你应该发起一个投票</small></h5>
                       <div class="ibox-tools">
                           <a class="collapse-link">
                               <i class="fa fa-chevron-up"></i>
                           </a>
                           <a href="#" data-toggle="dropdown" class="dropdown-toggle">
                               <i class="fa fa-wrench"></i>
                           </a>
                           <ul class="dropdown-menu dropdown-user">
                               <li><a href="#">Config option 1</a>
                               </li>
                               <li><a href="#">Config option 2</a>
                               </li>
                           </ul>
                           <a class="close-link">
                               <i class="fa fa-times"></i>
                           </a>
                       </div>
                   </div>
                   <div class="ibox-content">
                       <form class="form-horizontal" method="post"  id="form" name="form">
						<div class="form-group">
							<label class="col-sm-1 control-label">投票标题</label>
							<div class="col-sm-3">
								<input type="text" name="search_title" class="form-control" placeholder="输入投票标题进行搜索">
							</div>
							<label class="col-sm-1 control-label">创建时间</label>
							<div class="col-sm-4">
								<div class="row">
                                          <div id="data_1" class="col-md-6">
                                           <div class="input-group date">
											<span class="input-group-addon">
											<i class="fa fa-calendar"></i></span>
												<input type="text" name="startDate" class="form-control" placeholder="开始日期">
										</div>
                                          </div>
                                          <div id="data_1" class="col-md-6">
                                          	<div class="input-group date">
											<span class="input-group-addon">
											<i class="fa fa-calendar"></i></span>
												<input type="text" name="endDate" class="form-control" placeholder="结束日期">
										</div>
                                          </div>
                                      </div>
							</div>
						 	<div class="col-sm-3">
                                       <button type="button" class="btn btn-primary">搜索</button>
                                       <button type="reset" class="btn btn-white">重置</button>
                                  </div>
						</div>
					</form>
                          <table class="table table-responsive table-hover text-center">
                              <tbody id="voteListTBodyId">
                              	
                              </tbody>
                          </table>
                          <div id="laypageId" class="text-right">
                          </div>
				</div>
               </div>
           </div>
       </div>
      </div>

	<js>
    <!-- Color picker -->
    <script type="text/javascript" src="${ctx}/resource/v2/js/bootstrap-datepicker.js"></script>
    <script type="text/javascript" src="${ctx}/resource/v2/js/bootstrap-colorpicker.min.js"></script>
	
	<!-- laypage -->
	<script type="text/javascript" src="${ctx}/resource/laypage/laypage.js"></script>
	<script type="text/javascript" src="${ctx}/resource/laypage/laytpl.js"></script>
    <!-- iCheck -->
    <script src="${ctx}/resource/v2/js/icheck.min.js"></script>
    
    <script>
        $(document).ready(function () {
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
        });
    </script>
    <script>
        //datepicker
        $('#data_1 .input-group.date').datepicker({
            todayBtn: "linked",
            todayHighlight: true,
        	language: "zh",
        	format: "yyyy-mm-dd",
            keyboardNavigation: false,
            forceParse: false,
            calendarWeeks: true,
            autoclose: true,
        });
        $('#data_2 .input-group.date').datepicker({
            todayBtn: "linked",
            todayHighlight: true,
        	language: "zh",
        	format: "yyyy-mm-dd",
            keyboardNavigation: false,
            forceParse: false,
            calendarWeeks: true,
            autoclose: true
        });
      //搜索
        $("form [type='button']:eq(0)").click(function(){
      	  voteList.getPageList(1);
        });
       //get vote list
		$(function(){
      		voteList.getPageList(1);
       });
       var voteList = {
     		getPageList:function(curr){
				var load = layer.load(0);
	  			$.ajax({
	   				type: "post",
	   				url: "${ctx}/vote/myCreateListData.do",
	   				data: $("form").serialize()+"&currentPage="+curr,
	   				dataType:"json",
	   				success:function(data){
	   					var gettpl = document.getElementById("voteListTrId").innerHTML;
	   					laytpl(gettpl).render(data.resultMap,function(html){
	   						$("table tbody").html(html);
	  	 					document.getElementById("voteListTBodyId").innerHTML=html;
	   					});
	   					//显示分页
	   			        laypage({
	   			            cont: 'laypageId', //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
	   			            pages: data.page.totalPageCount, //通过后台拿到的总页数
	   			            curr: curr || 1, //当前页
	   			            skin: 'molv', //皮肤
	   			    	    first: 1, //将首页显示为数字1,。若不显示，设置false即可
	   			    	    last: false, //将尾页显示为总页数。若不显示，设置false即可
	   			    	    prev: '<', //若不显示，设置false即可
	   			    	    next: '>', //若不显示，设置false即可
	   			            jump: function(obj, first){ //触发分页后的回调
	   			                if(!first){ //点击跳页触发函数自身，并传递当前页：obj.curr
	   			                	voteList.getPageList(obj.curr);
	   			                }
	   			            }
	   			        });
	   			       layer.close(load);
	   				},
	  				error:function(d){
	  					layer.close(load);
	  					if(d.readyState == 0){
	  						layer.msg("服务器拒绝了我们的连接请求，请检查网络连接或者服务器是否启动", {time: 5000, icon:6});
	  					}
	  					console.log(JSON.stringify(d));
	  				}
	  			});
			}
   		};
       var del = function(tid){
   	           	$.ajax({
   	           		type: "post",
   	      				url: "${ctx}/vote/delete.do",
   	      				data: $("#form").serialize()+"&tid="+tid,
   	      				dataType:"json",
   	           		success:function(data){
   	           			if(data.flag=="success"){
   	   						layer.msg(data.message, {time: 1000, icon:6});
   	       					window.location.href="${ctx}/center/vote/myCreate.html"
   	   					}else{
   	   						layer.msg(data.message, {time: 1000, icon:6});
   	   					}
   	           		},
   	           		error:function(e){
   	     					if(e.readyState == 0){
   	     						layer.msg("服务器拒绝了我们的连接请求，请检查网络连接或者服务器是否启动", {time: 5000, icon:6});
   	     					}
   	     					console.log(JSON.stringify(e));
   	     				}
   	           	});
       }
       var upt = function(tid){
	           	$.ajax({
	           		type: "post",
	      				url: "${ctx}/vote/beforeUpdate.do",
	      				data: $("#form").serialize()+"&tid="+tid,
	      				dataType:"json",
	           			success:function(data){
	           			if(data.flag=="success"){
	       					window.location.href="${ctx}/center/vote/updateVoteDetail.html?tid="+tid
	   					}else{
	   						layer.msg(data.message, {time: 1000, icon:6});
	   					}
	           		},
	           		error:function(e){
	     					if(e.readyState == 0){
	     						layer.msg("服务器拒绝了我们的连接请求，请检查网络连接或者服务器是否启动", {time: 5000, icon:6});
	     					}
	     					console.log(JSON.stringify(e));
	     				}
	           	});
  			} 
    </script>
    <script id="voteListTrId" type="text/html">
		<tr class="info" style="font-weight: bold;">
        	<td>编号</td>
        	<td>投票主题</td>
        	<td>投票权限</td>
        	<td>投票热度</td>
        	<td>投票状态</td>
       	 	<td>创建时间</td>
        	<td>结束时间</td>
			<td>投票操作</td>
    	</tr>
		{{# for(var i = 0; i<d.length; i++){ }}
			<tr>
        		<td>{{i+1}}</td>
        		<td>
        			<a href="${ctx}/vote/router/route.do?topicId={{ d[i].tid }}">{{ d[i].title }}</a>
        			{{# if(d[i].diffDate < 7){ }}
        				<span class="label label-danger">NEW</span>
        			{{# } }}
       	 		</td>
        		<td>
        			{{# if(d[i].scope == '0'){ }}
        				所有人可投
        			{{# }else{  }}
        				会员可投
        			{{# } }}
        		</td>
        		<td class="text-warning">
        			{{# if(d[i].voteHot > 20){ }}
        				<span class="badge badge-danger">{{ d[i].voteHot }}</span>
        			{{# }else{  }}
        				<span class="badge badge-primary">{{ d[i].voteHot }}</span>
        			{{# } }}
	        	</td>
	        	{{# if(d[i].doStatus == 'doing'){ }}
						{{# if(d[i].voteStatus == '0'){ }}
							<td class="text-navy">
								未投票
							</td>
						{{# }else{ }}
							<td class="text-info">
								已投票
							</td>
						{{# } }}
        			{{# }else{  }}
						<td>
        					<del>已结束</del>
						</td>
        		{{# } }}
	        	<td>{{ d[i].create_time }}</td>
	        	<td>{{ d[i].deadline }}</td>
				<td>
					<button type="button" class="btn btn-sm btn-primary" onClick=upt('{{ d[i].tid }}')>修改</button>&nbsp;
					<button type="button" class="btn btn-sm btn-primary" onClick=del('{{ d[i].tid }}')>删除</button>
				</td>
	    	</tr>
	    {{# }  }}
	</script>
	</js>
</body>

</html>
